#!/usr/bin/env python
# encoding: utf-8
"""
fileutils_Test.py

Created by Orestis Markou on 2007-12-12.
Copyright (c) 2007 Orestis Markou. All rights reserved.
"""

import sys
import os


import unittest
from greeklish import fileutils
import re

class NormalTestCase(unittest.TestCase):
    def setUp(self):
        self.pattern = re.compile(r'(?P<greek>\w+)-(?P<count>\d+).*', re.UNICODE) 
        self.filename = 'fileutils_Test.file'
        f = open(self.filename, 'wb')
        f.write('να-645987-(0.030625033482)\n')
        f.write('testeetd34-234.0-(0.030625033482)\n')
        f.close()
    
    def tearDown(self):
        """docstring for tearDown"""
        os.remove(self.filename)
    
    def testSimple(self):
        bins = ['greek', 'count']
        res = fileutils.parse_word_file(self.filename, self.pattern, bins)
        self.assertEqual(res[0]['greek'], u'να')
        self.assertEqual(res[0]['count'], 645987.0)
        self.assertEqual(res[1]['greek'], u'testeetd34')
        self.assertEqual(res[1]['count'], 234.0)
    
    def testFailure1(self):
        pattern = re.compile(r'DUMMY')
        bins = ['greek', 'count']
        res = fileutils.parse_word_file(self.filename, pattern, bins)
        self.assertEqual(res, [])

    def testFailure1(self):
        bins = ['foo', 'bar']
        res = fileutils.parse_word_file(self.filename, self.pattern, bins)
        self.assertEqual(res, [])
    

if __name__ == '__main__':
    unittest.main()

